{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="type" id="n_range" lay-search="" class="layui-input">
                                <option value="">全部订单</option>
                                <option value="1">待付款</option>
                                <option value="2">待发货</option>
                                <option value="3">待收货</option>
                                <option value="4">待评价</option>
                                <option value="5">已完成</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="contract" lay-search="" class="layui-input">
                                <option value="">全部类型</option>
                                <option value="1">自营订单</option>
                                <option value="2">增补订单</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="oldnew" lay-search="" class="layui-input">
                                <option value="">不分新旧</option>
                                <option value="1">新APP订单</option>
                                <option value="2">旧APP订单</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <select name="schoolid" class="layui-input" xm-select="select2" xm-select-radio="" xm-select-search="" xm-select-search-type="dl">
                                <option value="" >全部学校</option>
                                {foreach name="schools" item="v"}
                                <option value="{$v.school_erp}">{$v.school_name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="购买开始时间" />
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="购买结束时间" />
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" style="width: 300px;" id="n_title" class="layui-input search" name="n_title" placeholder="订单号/收件人姓名/收件人手机号/快递单号"/>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" style="width: 90px;margin-left: 110px;" id="orderid" class="layui-input search" name="orderid" placeholder="订单id"/>
                        </div>
                        <div class="layui-input-inline" style="margin-left: 10px;">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty" lay-submit="" lay-filter="LAY-search">
                                重置
                            </button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 导出 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">
                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll"><i class="fa fa-print"></i> 导出汇总</a></li>
                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAllDetail"><i class="fa fa-print"></i> 导出明细</a></li>
                        </ul>
                    </div>
                </div>
                <!--操作框结束-->
                <div class="col-sm-12">
                <div class="input-group" >
                    <input type="text" disabled class="layui-input" id="tongji1" value="" style="border:1px solid red;color: red;width: 400px;" />
                </div>
            </div>
            </div>

            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--状态显示模板-->
                    <script type="text/html" id="pay_type">
                        {{# if(d.pay_type == 1){ }}
                        微信
                        {{# } }}
                        {{# if(d.pay_type == 2){ }}
                        支付宝
                        {{# } }}
                        {{# if(d.pay_type == 3){ }}
                        银联
                        {{# } }}
                    </script>
                    <!--状态显示模板-->
                    <script type="text/html" id="order_contract">
                        {{# if(d.order_contract == 1){ }}
                        自营订单
                        {{# } }}
                        {{# if(d.order_contract == 2){ }}
                        增补订单
                        {{# } }}
                    </script>
                    <!--状态显示模板-->
                    <script type="text/html" id="is_pay">
                        {{# if(d.is_pay == 0){ }}
                        待支付
                        {{# } }}
                        {{# if(d.is_pay == 1){ }}
                        已支付
                        {{# } }}
                        {{# if(d.is_pay == 2){ }}
                        已取消
                        {{# } }}
                    </script>
                    <!--状态显示模板-->
                    <script type="text/html" id="is_send">
                        {{# if(d.is_pay == 0){ }}
                        订单待支付
                        {{# } }}
                        {{# if(d.is_pay == 1){ }}
                            {{# if(d.is_send == 0){ }}
                            未发货
                            {{# } }}
                            {{# if(d.is_send == 1){ }}
                            已发货未收货
                            {{# } }}
                            {{# if(d.is_send == 2){ }}
                            已收货待评价
                            {{# } }}
                            {{# if(d.is_send == 3){ }}
                            已完成
                            {{# } }}
                        {{# } }}
                        {{# if(d.is_pay == 2){ }}
                        订单已取消
                        {{# } }}

                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <!-- -->
                        <!--<a href="javascript:;" onclick="wk.href('{:url('orderInfo')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="详情"><i class="fa fa-info">详情</i></a>-->
                        <a href="javascript:;" onclick="wk.layer_show('详情','{:url('orderInfo')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="详情"><i class="fa fa-info">详情</i></a>
                        {{# if(d.is_pay == 0){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderCancle')}','确定要关闭订单吗？')" class="btn btn-warning btn-xs m-r-xs" title="关闭订单"><i class="fa fa-edit">关闭订单</i></a>
                        {{# } }}
                        {{# if(d.is_pay == 1){ }}
                        <!--只要支付就可以查看发票-->
                            {{# if(d.fapiao_status == 1){ }}
                            <a href="javascript:;" onclick="wk.layer_show('发票信息', '{:url('fapiao')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="发票信息"><i class="fa fa-edit">发票信息</i></a>
                            {{# } }}
                            {{# if(d.is_send == 0){ }}
                            <a href="javascript:;" onclick="wk.layer_show('修改收货地址', '{:url('orderUpdateAddress')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="修改收货地址"><i class="fa fa-edit">修改收货地址</i></a>
                                {{# if(d.order_contract == 1){ }}
                                <a href="javascript:;" onclick="wk.layer_show('快递发货', '{:url('orderSend')}?order_id={{d.order_id}}&type=1')" class="btn btn-warning btn-xs m-r-xs" title="快递发货"><i class="fa fa-edit">快递发货</i></a>
                                {{# } }}
                            {{# } }}
                            {{# if(d.is_send >= 1){ }}
                            <a href="javascript:;" onclick="wk.layer_show('查看物流','{:url('orderWuliu')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="查看物流"><i class="fa fa-edit">查看物流</i></a>
                            <a href="javascript:;" onclick="wk.layer_show('修改物流信息', '{:url('orderSend')}?order_id={{d.order_id}}&type=2')" class="btn btn-warning btn-xs m-r-xs" title="修改物流"><i class="fa fa-edit">修改物流信息</i></a>
                            {{# } }}
                            {{# if(d.is_send == 3){ }}
                            <a href="javascript:;" onclick="wk.layer_show('查看评价', '{:url('orderComments')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看评价"><i class="fa fa-edit">查看评价</i></a>
                            {{# } }}
                        {{# } }}
                        {{# if(d.is_pay == 2){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                        {{# } }}
                        <!--<a href="javascript:;" onclick="wk.layer_show('查看评价', '{:url('orderComments')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看评价"><i class="fa fa-edit">查看评价</i></a>-->

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<textarea id="allidsForOut" class="hidden"></textarea>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Order/index")}'
            , response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type: 'numbers', width: 80, title: '序号'}
                , {field: 'order_no', width: '', title: '订单号', align: 'center'}
                , {field: 'order_contract', width: '', title: '订单类型', align: 'center', toolbar: '#order_contract'}
                , {field: 'first_good_name', width: '', title: '商品名字', align: 'center'}
                , {field: 'all_good_nums', width: '', title: '商品数量', align: 'center'}
                , {field: 'all_goods_price', width: '', title: '商品金额', align: 'center'}
                , {field: 'express_original_price', width: '', title: '运费', align: 'center'}
                , {field: 'total_price', width: '', title: '实付款', align: 'center'}
                , {field: 'school_name', width: '', title: '所在学校', align: 'center'}
                , {field: 'user_username', width: '', title: '用户昵称', align: 'center'}
                , {field: 'user_phone', width: '', title: '用户手机号', align: 'center'}
                , {field: 'created_at', width: '', title: '创建时间', align: 'center'}
                , {field: 'pay_type', width: '', title: '支付类型', align: 'center', toolbar: '#pay_type'}
                , {field: 'is_pay', width: '', title: '是否付款', align: 'center', toolbar: '#is_pay'}
                , {field: 'is_send', width: '', title: '订单状态', align: 'center', toolbar: '#is_send'}
                , {fixed: 'right', width: 430, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            , done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
                $('#tongji1').val('当前条件下总金额：'+res.allmoney+'元          总商品数量：'+res.allnums);
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("changeGoodStatus")}',obj);
        });
        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                wk.excelAll('',$('.layui-input').serialize(),"{:url('excelOutOrder')}");
            },
            excelAllDetail: function(){
                //导出Excel
                wk.excelAll('',$('.layui-input').serialize(),"{:url('excelOutDetail')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                , data = checkStatus.data;
            $.each(data, function (index, item) {
                ids.push(item['n_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>